<script setup>
import { RouterLink, RouterView, routerKey } from 'vue-router'
import { ref, reactive, computed, onMounted } from 'vue';
import { default as http, getImageUrl } from '@/utils/request.js'
import { useRouter } from 'vue-router'; //路由器
const router = useRouter(); //获取到 router 对象，用于编程式跳转导航
//跳转到登录页面
function toCommentView() {
    router.push("/commentsub");
}

const onClickLeft = () => router.push("/personal");
// Alt + Shift +F 整理代码格式
//倒计时
const time = ref(30 * 60 * 60 * 1000);

// 导航
const active = ref(1);


// 打开评论
// '/commentinfo/:commentId(\\d+)',
const toComment = function (commentId) {
    console.log("订单号:", commentId);
    router.push({path: "/commentinfo/" + commentId +"?name=zhangsan"});
}

// 可追评列表
const reCommentList = reactive([

]);
// 可追评列表  
const getReCommentList = () => {

    http.get("/user/info").then((response) => {
        console.log("获取个人信息= ", response);
        console.log("id:", response.data.data.userName);
        http.get("/user/comment/recomment/" + response.data.data.userName).then((res) => {
            reCommentList.splice(0); //todo 需要将原有的元素清空  
            res.data.data.list.forEach(order => {
                reCommentList.push(order);
            });
            console.log('获取可追评列表: ', res.data.data.list);
            console.log('reCommentList:', reCommentList);
            // resolve(); // 当获取待收货列表成功后，返回一个解析成功的Promise  
        }).catch(err => {
            reject(err); // 当请求失败时，返回一个请求失败的Promise  
        });

    }).catch(() => {
    });
};


// 打开评论
// /commentsub/:orderNumber(\\d+)
const toCommentSub = function (orderNumber) {
    console.log("订单号:", orderNumber);
    router.push({path: "/commentsub/" + orderNumber});
}

onMounted(() => {
    getReCommentList();
    // handleDelete(); 
    // 获取个人信息  

});

</script>


<template>
    <van-col span="24" class="nav_bar">
        <van-nav-bar title="我的评价" left-text="返回" :fixed="true" left-arrow @click-left="onClickLeft" />
    </van-col>

    <van-cell-group style="margin-top: 20px;">
        <van-tabs v-model:active="active" style="margin-right: 20px;">
            <van-tab title="待评价" to="/mycomment"></van-tab>
            <van-tab title="可追评" to=""></van-tab>
            <van-tab title="已评价" to="/aftercomment"></van-tab>
        </van-tabs>
    </van-cell-group>


    <div>
        <!-- <div > -->
        <div style="width:350px; color: #c8d175; ">
            <van-cell-group inset>
                <van-card v-for="rc in reCommentList" :key="rc.orderNumber" :num="rc.amount" :price="rc.orderPrice"
                    :desc="rc.details" :title="rc.sellName" :thumb="getImageUrl(rc.picture)"
                    style="margin-top: 10px; background-color:  #FFFFE0;" @click="toComment(rc.commentId)">
                    <template #tags>
                        <van-tag plain type="primary" style="flex-grow: 1; margin-right: 10px;">{{ rc.goodsName }}</van-tag>
                    </template>
                    <template #footer style="margin-left: 0%;">
                        <van-space size="1rem">
                            <van-button size="mini" @click.stop="toMessage">查看评价</van-button>
                            <van-button size="mini" @click.stop="toCommentSub(rc.orderNumber)">追评</van-button>
                        </van-space>
                    </template>
                </van-card>
            </van-cell-group><!--  -->
            <br>
        </div>
    </div>




    <RouterView />
</template>

<style scoped>
header {
    position: fixed;
    top: 0;
    width: 100%;
    z-index: 9999;
    line-height: 1.5;
    max-height: 100vh;
}


header {
    line-height: 1.5;
    max-height: 100vh;
}


nav {
    width: 100%;
    font-size: 12px;
    text-align: center;
    margin-top: 2rem;
}

nav a.router-link-exact-active {
    color: var(--color-text);
}

nav a.router-link-exact-active:hover {
    background-color: transparent;
}

nav a {
    display: inline-block;
    padding: 0 1rem;
    border-left: 1px solid var(--color-border);
}

nav a:first-of-type {
    border: 0;
}

@media (min-width: 1024px) {
    header {
        display: flex;
        place-items: center;
        padding-right: calc(var(--section-gap) / 2);
    }


    header .wrapper {
        display: flex;
        place-items: flex-start;
        flex-wrap: wrap;
    }

    nav {
        text-align: left;
        margin-left: -1rem;
        font-size: 1rem;
        padding: 1rem 0;
        margin-top: 1rem;
    }
}

.van-field {
    /* 调整每一行边距 */
    padding: 16px 15px;
}

.van-nav-bar {
    color: #d4e09f;
    width: 100%;
}

.full-width-card {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    padding: 10px;
    /* 根据需要调整 */
}

.nav_bar {
    position: relative;
    top: -32px;
    /* left:-32px;
    right: -32px; */
    margin: 2px -32px
}
</style>
